




/*
'===============================================================================
'  HNG.Portal.BL.TblViTriManagerBase
'===============================================================================
*/

using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using HNG.Portal.BLL;
using HNG.Portal.DAL;
using HNG.Portal.DAL.EntityClasses;
using HNG.Portal.DAL.FactoryClasses;
using HNG.Portal.DAL.HelperClasses;
using SD.LLBLGen.Pro.ORMSupportClasses;
using System.Windows.Forms;
namespace HNG.Portal.BLL
{
	public class TblViTriManagerBase
	{
	    
		#region ColumnNames
		
				public const String Field_Id="Id";
				
				public const String Field_LangId="LangId";
				
				public const String Field_Mota="Mota";
				
				public const String Field_Type="Type";
				
				public const String Field_TrangThai="TrangThai";
				
		#endregion	
		/// <summary>
		/// Purpose: Class constructor.
		/// </summary>
		public TblViTriManagerBase()
		{
			// Nothing for now.
		}
		public DataTable Clone()
		{
			DataTable dt = new DataTable();
						
			
			dt.Columns.Add(Field_Id,typeof(int));
			
						
			
			dt.Columns.Add(Field_LangId,typeof(int));
			
						
			
			dt.Columns.Add(Field_Mota,typeof(string));
			
						
			
			dt.Columns.Add(Field_Type,typeof(string));
			
						
			
			dt.Columns.Add(Field_TrangThai,typeof(bool));
			
			            
            return dt;			
		}
			
		public TblViTriEntity Convert_Entity(TblViTriEntity _TblViTriEntity,TblViTriEntity _TblViTriEntity_XML)
		{	
			
				
			_TblViTriEntity.Id= _TblViTriEntity_XML.Id;
				
			_TblViTriEntity.LangId= _TblViTriEntity_XML.LangId;
				
			_TblViTriEntity.Mota= _TblViTriEntity_XML.Mota;
				
			_TblViTriEntity.Type= _TblViTriEntity_XML.Type;
				
			_TblViTriEntity.TrangThai= _TblViTriEntity_XML.TrangThai;
				
			
			return _TblViTriEntity;
		}	
		
			
		public void InsertCollection(EntityCollection _Collection)
		{
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
            {
                adapter.SaveEntityCollection(_Collection);
            }
		}

		public TblViTriEntity Insert(TblViTriEntity TblViTriEntity)
		{
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.SaveEntity(TblViTriEntity, true);
			}
			return TblViTriEntity;
		}

		
		public TblViTriEntity Insert(int Id, int LangId, string Mota, string Type, bool TrangThai)
		{
			TblViTriEntity _TblViTriEntity = new TblViTriEntity();
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				
				_TblViTriEntity.Id = Id;
				_TblViTriEntity.LangId = LangId;
				_TblViTriEntity.Mota = Mota;
				_TblViTriEntity.Type = Type;
				_TblViTriEntity.TrangThai = TrangThai;
				adapter.SaveEntity(_TblViTriEntity, true);
			}
			return _TblViTriEntity;
		}

		public TblViTriEntity Insert(int LangId, string Mota, string Type, bool TrangThai)
		{
			TblViTriEntity _TblViTriEntity = new TblViTriEntity();
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				
				_TblViTriEntity.LangId = LangId;
				_TblViTriEntity.Mota = Mota;
				_TblViTriEntity.Type = Type;
				_TblViTriEntity.TrangThai = TrangThai;
				adapter.SaveEntity(_TblViTriEntity, true);
			}
			return _TblViTriEntity;
		}

		public bool Update(TblViTriEntity _TblViTriEntity)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				RelationPredicateBucket filter = new RelationPredicateBucket();
				IPredicateExpression _PredicateExpression = new PredicateExpression();
				_PredicateExpression.Add(TblViTriFields.Id == _TblViTriEntity.Id);
					
				filter.PredicateExpression.Add(_PredicateExpression);

				adapter.UpdateEntitiesDirectly(_TblViTriEntity, filter);
				toReturn = true;
			}
			return toReturn;
		}
		
		public bool Update(TblViTriEntity _TblViTriEntity, RelationPredicateBucket filter)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.UpdateEntitiesDirectly(_TblViTriEntity, filter);
				toReturn = true;
			}
			return toReturn;
		}

		public bool Update(int Id, int LangId, string Mota, string Type, bool TrangThai)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				TblViTriEntity _TblViTriEntity = new TblViTriEntity(Id);
				if (adapter.FetchEntity(_TblViTriEntity))
				{
				
					_TblViTriEntity.LangId = LangId;
					_TblViTriEntity.Mota = Mota;
					_TblViTriEntity.Type = Type;
					_TblViTriEntity.TrangThai = TrangThai;
					adapter.SaveEntity(_TblViTriEntity, true);
					toReturn = true;
				}
			}
			return toReturn;
		}

		public bool Delete(int Id)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				TblViTriEntity _TblViTriEntity = new TblViTriEntity(Id);
				if (adapter.FetchEntity(_TblViTriEntity))
				{
					adapter.DeleteEntity(_TblViTriEntity);
					toReturn = true;
				}
			}
			return toReturn;
		}
		
		public void DeleteAll() 
		{
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.DeleteEntitiesDirectly("TblViTriEntity", null);
			}
		}
		
		
		public int DeleteById(int Id)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblViTriFields.Id == Id);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblViTriEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByLangId(int LangId)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblViTriFields.LangId == LangId);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblViTriEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByMota(string Mota)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblViTriFields.Mota == Mota);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblViTriEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByType(string Type)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblViTriFields.Type == Type);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblViTriEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByTrangThai(bool TrangThai)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblViTriFields.TrangThai == TrangThai);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblViTriEntity", filter);
			}
			return toReturn;
		}
		

		
		public TblViTriEntity SelectOne(int Id)
		{
			TblViTriEntity toReturn = null;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				TblViTriEntity _TblViTriEntity = new TblViTriEntity(Id);
				if (adapter.FetchEntity(_TblViTriEntity))
				{
					toReturn = _TblViTriEntity;
				}
			}
			return toReturn;
		}

		// Return EntityCollection
		public EntityCollection SelectAll()
		{
			EntityCollection _TblViTriCollection = new EntityCollection( new TblViTriEntityFactory());
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblViTriCollection, null, 0, null);
			}
			return _TblViTriCollection;
		}
		
		// Return DataTable
		public DataTable SelectAllRDT()
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblViTriCollection = new EntityCollection(new TblViTriEntityFactory());
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblViTriCollection.EntityFactoryToUse.CreateFields(), toReturn, null, true);
			}
			return toReturn;
		}

		
		// Return EntityCollection
		public EntityCollection SelectById(int Id)
		{
			EntityCollection _TblViTriCollection = new EntityCollection(new TblViTriEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblViTriFields.Id == Id);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblViTriCollection, filter, 0, null);
			}
			return _TblViTriCollection;
		}
		
		// Return DataTable
		public DataTable SelectByIdRDT(int Id)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblViTriCollection = new EntityCollection(new TblViTriEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblViTriFields.Id == Id);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblViTriCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return EntityCollection
		public EntityCollection SelectByLangId(int LangId)
		{
			EntityCollection _TblViTriCollection = new EntityCollection(new TblViTriEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblViTriFields.LangId == LangId);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblViTriCollection, filter, 0, null);
			}
			return _TblViTriCollection;
		}
		
		// Return DataTable
		public DataTable SelectByLangIdRDT(int LangId)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblViTriCollection = new EntityCollection(new TblViTriEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblViTriFields.LangId == LangId);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblViTriCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return EntityCollection
		public EntityCollection SelectByMota(string Mota)
		{
			EntityCollection _TblViTriCollection = new EntityCollection(new TblViTriEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblViTriFields.Mota == Mota);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblViTriCollection, filter, 0, null);
			}
			return _TblViTriCollection;
		}
		
		// Return DataTable
		public DataTable SelectByMotaRDT(string Mota)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblViTriCollection = new EntityCollection(new TblViTriEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblViTriFields.Mota == Mota);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblViTriCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return EntityCollection
		public EntityCollection SelectByType(string Type)
		{
			EntityCollection _TblViTriCollection = new EntityCollection(new TblViTriEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblViTriFields.Type == Type);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblViTriCollection, filter, 0, null);
			}
			return _TblViTriCollection;
		}
		
		// Return DataTable
		public DataTable SelectByTypeRDT(string Type)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblViTriCollection = new EntityCollection(new TblViTriEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblViTriFields.Type == Type);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblViTriCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return EntityCollection
		public EntityCollection SelectByTrangThai(bool TrangThai)
		{
			EntityCollection _TblViTriCollection = new EntityCollection(new TblViTriEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblViTriFields.TrangThai == TrangThai);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblViTriCollection, filter, 0, null);
			}
			return _TblViTriCollection;
		}
		
		// Return DataTable
		public DataTable SelectByTrangThaiRDT(bool TrangThai)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblViTriCollection = new EntityCollection(new TblViTriEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblViTriFields.TrangThai == TrangThai);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblViTriCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		

	}
}
